# student/migrations/0002_seed_student.py
from django.db import migrations
from django.utils import timezone
import random
import string

def seed_student(apps, schema_editor):
    Student = apps.get_model('student', 'Student')  # app_label = 'student'
    bulk = []
    for i in range(1, 201):          # 200 条
        bulk.append(Student(
            name=f'学生{string.ascii_uppercase[i%26]}{i:03d}',
            age=random.randint(16, 25),
            email=f'student{i:03d}@example.com',
            phone=f'1{random.randint(3,9):03d}{random.randint(0,99999999):08d}',
            status=random.choice([0,1,2]),
            created_at=timezone.now(),
            updated_at=timezone.now(),
        ))
    Student.objects.bulk_create(bulk, batch_size=500)

def reverse_seed(apps, schema_editor):
    Student = apps.get_model('student', 'Student')
    Student.objects.filter(email__endswith='@example.com').delete()

class Migration(migrations.Migration):
    dependencies = [('student', '0001_initial')]   # 前一条迁移文件名按实际写
    operations = [migrations.RunPython(seed_student, reverse_seed)]